package com.example.wastes.orderPruduct.controller;

import com.example.wastes.common.pojo.OrderPruduct;
import com.example.wastes.common.util.R;
import com.example.wastes.orderPruduct.service.OrderPruductService;
import com.example.wastes.orderPruduct.service.impl.OrderPruductServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class OrderPruductController {
    @Autowired
    private OrderPruductService orderPruductService;
    @Autowired
    private OrderPruductServiceImpl orderPruductServiceImpl;
    @GetMapping("/getAllorderPruduct")
    @ApiOperation("查询订单详情所有")
    public R getAllorderPruduct(){
        return new R(true,orderPruductService.list());
    }
    @PostMapping("/saveorderPruduct")
    @ApiOperation("添加订单详情")
    public R saveorderPruduct(@RequestBody OrderPruduct orderPruduct){
        return new R(orderPruductService.save(orderPruduct));
    }
    @PutMapping("/updateorderPruduct")
    @ApiOperation("修改订单详情")
    public R updateorderPruduct(@RequestBody OrderPruduct orderPruduct){
        return new R(orderPruductService.updateById(orderPruduct));
    }
    @DeleteMapping("/deleteorderPruduct")
    @ApiOperation("删除订单详情")
    public R deleteorderPruduct(Integer id){
        return new R(orderPruductService.removeById(id));
    }
    @GetMapping("/findAllOP")
    @ApiOperation("Articles和OrderPruduct表之间的关联“订单详情的内容")
    public R findAllOP(Integer oid){
        return  new R(true,orderPruductService.findAllOP(oid));
    }

    @GetMapping("/sell/{uid}/{oid}/{aid}/{number}")
    public String ordersell(@PathVariable int uid,@PathVariable int oid,@PathVariable int aid,@PathVariable int number){
        try {
            orderPruductService.sumprice(uid,oid,aid,number);
            return "下单成功";
        }catch (Exception e){
            e.printStackTrace();
            return "下单失败";
        }
    }
}
